Skip to content

Improve detection & usage of deno/bun #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 19, 2025
Merged

Improve detection & usage of deno/bun #1333

merged 9 commits into from
Jun 19, 2025

Conversation

xenova
Copy link
Collaborator

@xenova xenova commented Jun 2, 2025

Closes #1332

  • Uses node: prefixes for built-in libraries, ensuring standardization across node, bun, and deno runtimes
  • Disable browser cache by default in Deno runtime (because the web cache API is available, but our URLs are not valid because we are using relative file paths due to the filesystem access we have)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova
Copy link
Collaborator Author

xenova commented Jun 19, 2025

For posterity, I was working on improving cloudflare worker integration, but I wasn't able to get it working. Here are things I learned (mainly for future me):

  1. You can use conditional exports that cloudflare workers will use specifically:
  "exports": {
    ...
    "worker": {
      "types": "./types/transformers.d.ts",
      "default": "./dist/transformers.js"
    },
    ...
  },
  1. Cloudflare workers don't support relative URLs (e.g., new URL('.') is invalid)
  2. Cloudflare workers don't support .node addon binaries (Node Addon binaries in Cloudflare Workers? cloudflare/workerd#1905 (comment)). This is unlikely to change in future.
  3. Cloudflare workers disable wasm code generation ([🐛 Bug]: WebAssembly.instantiate(): Wasm code generation disallowed by embedder cloudflare/next-on-pages#704) - this is a security consideration and is unlikely to change in future.
  4. You can detect cloudflare worker environment simply with typeof globalThis.Cloudflare !== 'undefined'

@xenova xenova merged commit a5847c9 into main Jun 19, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read properties of undefined (reading 'create')
2 participants